<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php $this->load->view('bm/common/header'); ?>
<body>
<!-- 头部 -->
<?php $this->load->view('bm/common/top'); ?>
<!-- /头部 -->

<!-- 边栏 -->
<?php $this->load->view('bm/common/sidebar'); ?>
<!-- /边栏 -->

<!-- 内容区 -->
<div id="main-content">
	<div id="top-alert" class="fixed alert alert-error" style="display: none;">
		<button class="close fixed" style="margin-top: 4px;">&times;</button>
		<div class="alert-content">这是内容</div>
	</div>
	<div id="main" class="main">
		<!-- nav -->
		<!-- nav -->
		<script type="text/javascript" src="/static/uploadify/jquery.uploadify.min.js"></script>
		<div class="main-title cf">
			<h2>
				新增文章文档 [<a href="/index.php?s=/admin/article/index/cate_id/1.html">博客</a><i class="ca"></i><a href="/index.php?s=/admin/article/index/cate_id/2.html">默认分类</a>]
			</h2>
		</div>
		<!-- 标签页导航 -->
		<div class="tab-wrap">
			<ul class="tab-nav nav">
				<li data-tab="tab1" class="current"><a href="javascript:void(0);">基础</a></li>
				<li data-tab="tab2"><a href="javascript:void(0);">扩展</a></li>
			</ul>
			<div class="tab-content">
				<!-- 表单 -->
				<form id="form" action="" method="post" class="form-horizontal">
					<!-- 基础文档模型 -->
					<div id="tab1" class="tab-pane in tab1">
						<div class="form-item cf">
							<label class="item-label">标题<span class="check-tips">（文档标题）</span></label>
							<div class="controls"><input type="text" class="text input-large" name="title" value="<?php echo $info['title'];?>"></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">标识<span class="check-tips">（同一根节点下标识不重复）</span></label>
							<div class="controls"><input type="text" class="text input-large" name="name" value="<?php echo $info['name'];?>"></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">文章分类<span class="check-tips"></span></label>
							<div class="controls">
								<select name="category_id" id="category_id">
									<option value="">无上级</option>
									<?php echo $tree_to_select;?>
								</select>
							</div>
						</div>
						<div class="form-item cf">
							<label class="item-label">关键字<span class="check-tips"></span></label>
							<div class="controls"><input type="text" class="text input-large" name="keyword" value="<?php echo $info['keyword'];?>"></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">描述<span class="check-tips"></span></label>
							<div class="controls">
								<label class="textarea input-large">
									<textarea name="description"><?php echo $info['description'];?></textarea>
								</label></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">文章内容<span class="check-tips"></span></label>
							<div class="controls">
								<label class="textarea">
									<script id="editor_content" type="text/plain"  name="content"><?php echo $info['content'];?></script>
									<input type="hidden" name="parse" value="2"> </label></div>
						</div>
					</div>
					<div id="tab2" class="tab-pane tab2">
						<div class="form-item cf">
							<label class="item-label">截至时间<span class="check-tips">（0-永久有效）</span></label>
							<div class="controls">
								<input type="text" name="dateline" class="text input-large time" value="" placeholder="请选择时间"/></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">详情页显示模板<span class="check-tips">（参照display方法参数的定义）</span></label>
							<div class="controls"><input type="text" class="text input-large" name="template" value=""></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">外链<span class="check-tips">（0-非外链，大于0-外链ID,需要函数进行链接与编号的转换）</span></label>
							<div class="controls"><input type="text" class="text input-large" name="link_id" value=""></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">内容类型<span class="check-tips"></span></label>
							<div class="controls">
								<select name="type">
									<option value="1">目录</option>
									<option value="2" selected>主题</option>
									<option value="3">段落</option>
								</select></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">附件数量<span class="check-tips"></span></label>
							<div class="controls">
								<input type="text" class="text input-large" name="attach" value=""></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">浏览量<span class="check-tips"></span></label>
							<div class="controls">
								<input type="text" class="text input-large" name="view" value=""></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">推荐位<span class="check-tips">（多个推荐则将其推荐值相加）</span></label>
							<div class="controls">
								<label class="checkbox">
									<input type="checkbox" value="1" name="position">列表推荐 </label><label
										class="checkbox">
									<input type="checkbox" value="2" name="position">频道页推荐 </label><label
										class="checkbox">
									<input type="checkbox" value="4" name="position">首页推荐 </label></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">评论数<span class="check-tips"></span></label>
							<div class="controls">
								<input type="text" class="text input-large" name="comment" value=""></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">优先级<span class="check-tips">（越高排序越靠前）</span></label>
							<div class="controls">
								<input type="text" class="text input-large" name="level" value=""></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">可见性<span class="check-tips"></span></label>
							<div class="controls">
								<label class="radio"><input type="radio" value="0" name="display">不可见 </label>
								<label class="radio"><input type="radio" value="1" name="display">所有人可见 </label></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">创建时间<span class="check-tips"></span></label>
							<div class="controls"><input type="text" name="create_time" class="text input-large time" value="" placeholder="请选择时间"/></div>
						</div>
						<div class="form-item cf">
							<label class="item-label">封面<span class="check-tips">（0-无封面，大于0-封面图片ID，需要函数处理）</span></label>
							<div class="controls">
								<div class="controls">
									<input type="file" id="images">
									<input type="hidden" name="cover_id" id="cover_id_cover_id"/>
									<div class="upload-img-box"></div>
								</div>
								<script type="text/javascript">
									//上传图片
									/* 初始化上传插件 */
									$("#upload_picture_cover_id").uploadify({
										"height": 30,
										"swf": "/static/uploadify/uploadify.swf",
										"fileObjName": "download",
										"buttonText": "上传图片",
										"uploader": "/index.php?s=/admin/file/uploadpicture/session_id/j59r50ukev1om7u4gd8cagkft2.html",
										"width": 120,
										'removeTimeout': 1,
										'fileTypeExts': '*.jpg; *.png; *.gif;',
										"onUploadSuccess": uploadPicturecover_id
									});

									function uploadPicturecover_id(file, data) {
										var data = $.parseJSON(data);
										var src = '';
										if (data.status) {
											$("#cover_id_cover_id").val(data.id);
											src = data.url || '' + data.path
											$("#cover_id_cover_id").parent().find('.upload-img-box').html(
													'<div class="upload-pre-item"><img src="' + src + '"/></div>'
											);
										} else {
											updateAlert(data.info);
											setTimeout(function () {
												$('#top-alert').find('button').click();
												$(that).removeClass('disabled').prop('disabled', false);
											}, 1500);
										}
									}
								</script>
							</div>
						</div>
						<div class="form-item cf">
							<label class="item-label">收藏数<span class="check-tips"></span></label>
							<div class="controls">
								<input type="text" class="text input-large" name="bookmark" value=""></div>
						</div>
					</div>
					<div class="form-item cf">
						<button class="btn submit-btn hidden" id="submit" type="submit" target-form="form-horizontal">确 定
						</button>
						<a class="btn btn-return" href="/index.php?s=/admin/article/index/cate_id/2.html">返 回</a>
						<button class="btn save-btn" url="/index.php?s=/admin/article/autosave.html"
								target-form="form-horizontal" id="autoSave">
							存草稿
						</button>
						<input type="hidden" name="id" value="<?php echo $info['id'];?>"/>
					</div>
				</form>
			</div>
		</div>

	</div>
	<?php $this->load->view('bm/common/copyright'); ?>
</div>
<!-- /内容区 -->
<script type="text/javascript">
	(function () {
		var ThinkPHP = window.Think = {
			"ROOT": "", //当前网站地址
			"APP": "/index.php?s=", //当前项目地址
			"PUBLIC": "/Public", //项目公共目录地址
			"DEEP": "/", //PATHINFO分割符
			"MODEL": ["3", "1", "html"],
			"VAR": ["m", "c", "a"]
		}
	})();
</script>
<script type="text/javascript" src="/static/think.js"></script>
<script type="text/javascript" src="/static/Admin/js/common.js"></script>
<script type="text/javascript">

	//设定分类选择
	$("#category_id option").each(function() {
		if($(this).val()==<?php echo $info['category_id'];?>){
			$(this).prop('selected',true);
		}
	});

	+function () {
		var $window = $(window), $subnav = $("#subnav"), url;
		$window.resize(function () {
			$("#main").css("min-height", $window.height() - 130);
		}).resize();

		/* 左边菜单高亮 */
		url = window.location.pathname + window.location.search;
		url = url.replace(".html", "")
				.replace(/(\/(p)\/\d+)|(&p=\d+)|(\/(id)\/\d+)|(&id=\d+)/, "");
		$subnav.find("a[href^='" + url + "']").parent().addClass("current");

		/* 左边菜单显示收起 */
		$("#subnav").on("click", "h3", function () {
			var $this = $(this);
			$this.find(".icon").toggleClass("icon-fold");
			$this.next().slideToggle("fast").siblings(".side-sub-menu:visible").prev("h3").find("i").addClass("icon-fold").end().end().hide();
		});

		$("#subnav h3 a").click(function (e) {
			e.stopPropagation()
		});

		/* 头部管理员菜单 */
		$(".user-bar").mouseenter(function () {
			var userMenu = $(this).children(".user-menu ");
			userMenu.removeClass("hidden");
			clearTimeout(userMenu.data("timeout"));
		}).mouseleave(function () {
			var userMenu = $(this).children(".user-menu");
			userMenu.data("timeout") && clearTimeout(userMenu.data("timeout"));
			userMenu.data("timeout", setTimeout(function () {
				userMenu.addClass("hidden")
			}, 100));
		});

		/* 表单获取焦点变色 */
		$("form").on("focus", "input", function () {
			$(this).addClass('focus');
		}).on("blur", "input", function () {
			$(this).removeClass('focus');
		});
		$("form").on("focus", "textarea", function () {
			$(this).closest('label').addClass('focus');
		}).on("blur", "textarea", function () {
			$(this).closest('label').removeClass('focus');
		});

		// 导航栏超出窗口高度后的模拟滚动条
		var sHeight = $(".sidebar").height();
		var subHeight = $(".subnav").height();
		var diff = subHeight - sHeight; //250
		var sub = $(".subnav");
		if (diff > 0) {
			$(window).mousewheel(function (event, delta) {
				if (delta > 0) {
					if (parseInt(sub.css('marginTop')) > -10) {
						sub.css('marginTop', '0px');
					} else {
						sub.css('marginTop', '+=' + 10);
					}
				} else {
					if (parseInt(sub.css('marginTop')) < '-' + (diff - 10)) {
						sub.css('marginTop', '-' + (diff - 10));
					} else {
						sub.css('marginTop', '-=' + 10);
					}
				}
			});
		}
	}();
</script>

<link href="/static/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<link href="/static/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">
<link href="/static/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/static/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">

	Think.setValue("type", "");
	Think.setValue("display", 0);

	$('#submit').click(function () {
		$('#form').submit();
	});

	$(function () {
		$('.time').datetimepicker({
			format: 'yyyy-mm-dd hh:ii',
			language: "zh-CN",
			minView: 2,
			autoclose: true
		});
		showTab();

		//保存草稿
		var interval;
		$('#autoSave').click(function () {
			var target_form = $(this).attr('target-form');
			var target = $(this).attr('url')
			var form = $('.' + target_form);
			var query = form.serialize();
			var that = this;

			$(that).addClass('disabled').attr('autocomplete', 'off').prop('disabled', true);
			$.post(target, query).success(function (data) {
				if (data.status == 1) {
					updateAlert(data.info, 'alert-success');
					$('input[name=id]').val(data.data.id);
				} else {
					updateAlert(data.info);
				}
				setTimeout(function () {
					$('#top-alert').find('button').click();
					$(that).removeClass('disabled').prop('disabled', false);
				}, 1500);
			})

			//重新开始定时器
			clearInterval(interval);
			autoSaveDraft();
			return false;
		});

		//Ctrl+S保存草稿
		$('body').keydown(function (e) {
			if (e.ctrlKey && e.which == 83) {
				$('#autoSave').click();
				return false;
			}
		});

		//每隔一段时间保存草稿
		function autoSaveDraft() {
			interval = setInterval(function () {
				//只有基础信息填写了，才会触发
				var title = $('input[name=title]').val();
				var name = $('input[name=name]').val();
				var des = $('textarea[name=description]').val();
				if (title != '' || name != '' || des != '') {
					$('#autoSave').click();
				}
			}, 1000 * parseInt(60));
		}

		autoSaveDraft();
	});
</script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
	//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	var ue = UE.getEditor('editor_content',{initialFrameWidth:'100%',initialFrameHeight:550});
</script>
</body>
</html>
